﻿
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>页面检索配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
    <script type="text/html" id="barDemo">
        <a title="编辑" href="javascript:;" lay-event="edit" id="frmEdit"><i class="layui-icon">&#xe642;</i></a>
        <a title="删除" href="javascript:;" lay-event="del" id="frmDel"><i class="layui-icon">&#xe640;</i></a>
    </script>
</head>
<body>
    <div class="layui-fluid">
        <ul lay-bar="disabled" class="mWebBanner" >
              <li class="layui-nav-item" style="float:left;">
                <button id="btn-update" type="button" name="btn_update" onclick="loadData()" class="buttonCss">
                   检索查询
                </button>
            </li>
            <li class="layui-nav-item" style="float:left;margin-left:3%">
                <button id="btn-update" type="button" name="btn_update" onclick="AddData()" class="buttonCss">
                   确认添加
                </button>
            </li>
        </ul>

        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="dForm" id="dForm">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <input type="text" name="fieldCode" placeholder="字段编码" class="layui-input" id="fieldCode">
                                </div>
                                <div class="layui-inline ">
                                    <input type="text" name="fieldName" placeholder="字段名称" class="layui-input" id="fieldName">
                                </div>
                                <div class="layui-inline">
                                    <select id="tCode" name="tCode" lay-filter="mq" lay-search>
                                        <option value="">所属菜单</option>
                                    </select>
                                </div>
                                 <div class="layui-inline">
                                <select id="fieldType" name="fieldType">
                                <option value="">数据类型</option>
                               </select>
                                </div>

                                <div class="layui-inline ">
                                    <select id="singleRow" name="singleRow">
                                        <option value="">是否单行</option>
                                        <option value="0">否</option>
                                        <option value="1">是</option>
                                    </select>
                                </div>
                                <input type="text" name="gCode" placeholder="分组编码" class="layui-input" id="gCode" style="width:16%;float:left">
                                <input type="text" name="dSoure" placeholder="数据源" class="layui-input" id="dSoure" style="width:77%;float:left;margin-left:1.5%">
                            </div>
                       
                        </form>
                    </div>

                    <div class="layui-card-body  layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>
    var currPage = 1;//首先默认值为1，防止出错
    var menuCode="";
    var dUrl = "../System/getDataList?dataType=tcc&condition=";
    /**
    数据加载
    **/
    function loadData() {
       var dataUrl = dUrl + $("#tCode").val();
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#list'
                , cols: [[ //标题栏
                    { field: 'fieldCode', title: '字段编码', width: 100 }
                    , { field: 'fieldName', title: '字段名称', width: 130 }
                    , { field: 'fieldType', title: '字段类型', width: 120 }
                    , { field: 'dSoure', title: '数据源', width: 300 }
                    , { field: 'singleRow', title: '是否单行', width: 100 }
                    , { field: 'right', title: '数据操作', toolbar: '#barDemo', width: 110, fixed: 'right' }
                ]], done: function (res, curr, count) {
                    currPage = curr;
                    TablePowerHide();
                }
                , url: dataUrl
                , skin: 'row' //表格风格
                , even: true
                , page: false //是否显示分页
                , limits: [15, 20, 30]
                , limit: 15 //每页默认显示的数量
                , id: "tData"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == 'del') {
                    layer.confirm('确认要删除该数据？', function (index) {
                        var info = DelData(data);
                        if (info.result) {
                            obj.del();
                        } else {
                            layer.msg(info.message);
                        }
                        layer.close(index);
                    });
                } else if (obj.event == 'edit') {
                    $.each(data, function (name, value) {
                        if (name == "fieldType" || name == "tCode" || name == "singleRow") {
                            $("#" + name + " option[value='" + value + "'] ").attr("selected", true);
                        } else {
                            $("input[ name='" + name + "']").val(value);
                        }
                    });
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
               

            });

        });
    }

    var webCode = "";
    $(function () {
        // WebPowersShow();
        webCode = getUrlVariable("menuCode");
        BannerData(webCode, "bDiv");
        MenuInfo();
        menuCode = getUrlVariable("menuCode");
        DictionaryDropDown("fdType", "fieldType", "");
        loadData();
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                loadData();
            }
        });
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(mq)', function (data) {
                if (data.value != undefined && data.value != "") {
                    loadData();
                }
            });
        });
    })

    function AddData() {
        var datas = JSON.stringify(FormToJson("dForm"));
        $.ajax({
            url: "../System/AddQueField",
            data: { datas: datas },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (rsl) {
                if (rsl.result) {
                    layer.msg("保存成功");
                    loadData();
                } else {
                    layer.msg(rsl.message);
                }
            }
        });
        
    }
    /**
    删除菜单方法
    **/
    function DelData(datas) {
        var info = undefined;
        $.ajax({
            url: "../System/DelQueField",
            data: { datas: JSON.stringify(datas) },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {

                info = data;
            }
        });
        return info;
    }
    /**
     * 获取顶级菜单
     * **/
    function MenuInfo() {
        $.ajax({
            url: "../System/getEnableMenuInfo",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.result) {
                    var datas = data.data;
                    for (var i = 0; i < datas.length; i++) {
                        if (datas[i]["menuCode"] != "") {
                            $("#tCode").append("<option value=\"" + datas[i]["menuCode"] + "\" >" + datas[i]["menuName"] + "(" + datas[i]["menuCode"] + ")" + "</option>");
                        }
                    }
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        });
    }
</script>